<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>五指山污水处理系统</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="<%=request.getContextPath()%>/huazhi/lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="<%=request.getContextPath()%>/huazhi/css/public.css" media="all">
    <link rel="stylesheet" href="<%=request.getContextPath()%>/css/logincss/layout.css" media="all">
    <link rel="shortcut icon" href="<%=request.getContextPath()%>/huazhi/images/favicon.ico"/>
</head>
<style>
    /* 底部固定区域 */
    .layui-layout-admin .layui-footer {
        padding: 10px 0;
        text-align: center;
    }

    .layui-layout-admin .layui-footer {
        background-color: #fff;
    }

    .el-input__suffix {
        position: absolute;
        height: 100%;
        right: 5px;
        top: 0;
        text-align: center;
        color: #c0c4cc;
        transition: all .3s;
        pointer-events: none;
    }

</style>
<body>
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <form class="layui-form" lay-filter="component-form-element" id="form">
            <input type="hidden" name="tid">
                <div class="layui-tab layui-tab-brief">
                    <ul class="layui-tab-title">
                        <li class="layui-this">基本信息</li>
                        <li>文件信息</li>
                    </ul>
                    <div class="layui-tab-content" style="height: auto">
                        <div class="layui-tab-item layui-show" id="onecontent">
                            <div class="layui-form-item">
                                <div class="layui-col-lg6">
                                    <div class="layui-col-xs11">
                                        <label class="layui-form-label">档案名称</label>
                                        <div class="layui-input-block">
                                            <input type="text" name="name" lay-verify="name"
                                                   autocomplete="off" placeholder="请输入档案名称"
                                                   class="layui-input">
                                        </div>
                                    </div>
                                    <div class="layui-col-xs1">
                                        <div class="layui-form-mid layui-word-aux"
                                             style="color: red !important;padding: 10px !important;">*
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <div class="layui-col-lg6">
                                    <div class="layui-col-xs3" id="file">
                                        <label class="layui-form-label">档案文件</label>
                                        <span class="layui-btn layui-btn-primary">选择文件
                                            <input lay-verify="file" type="file" id="changefile" class="uploadImg" name="uploadFile" multiple="multiple">
                                        </span>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="layui-tab-item">
                            <table class="layui-hide" id="files" lay-filter="filesTables"></table>
                            <div id="laypage"></div>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item layui-layout-admin">
                    <div class="layui-footer" style="left: 0;padding: 0px;">
                        <button class="layui-btn" lay-submit lay-filter="*" id="pushButton">立即提交</button>
                    </div>
                </div>
                <input type="hidden" id="username" value="${user.name}">
                <input type="hidden" id="datetime">
                <input type="hidden" id="fileupdate" value="0">
                <input type="hidden" id="filetid">
                <input type="hidden" id="filetype" value="law">
            </form>
        </div>
    </div>
</div>
<script src="<%=request.getContextPath()%>/huazhi/lib/layui-v2.5.5/layui.all.js"></script>
<script src="<%=request.getContextPath()%>/huazhi/js/lay-config.js?v=1.0.4" charset="utf-8"></script>
<script src="<%=request.getContextPath()%>/huazhi/lib/jquery-3.4.1/jquery-3.4.1.min.js"></script>
<input type="hidden" id="curnum" value="1">
<script type="text/html" id="table-files">
    {{#  if($("#fileupdate").val() == '0'){ }}
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="info">下载</a>
    {{#  } }}
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<script>
    function child(tid){
        $("#filetid").val(tid);
        layui.use(['form', 'layer','table','laypage','laydate','files'], function () {
            var $ = layui.$
                , form = layui.form
                , laydate = layui.laydate
                , laypage = layui.laypage
                , layer = layui.layer
                , table = layui.table;
            laydate.render({
                elem:'#datetime',
                type:'datetime',
                value:new Date(),
            });
            $.ajax({
                type: "get",
                url: "<%=request.getContextPath()%>/rest/base/getLawByTid",
                dataType: "json",
                async: false,
                data: "tid=" + tid,
                success: function (data) {
                    initfiles(data.files);
                    form.val("component-form-element", data);
                    // var pNode = document.getElementById("file");
                    // var filename = "";
                    // var files = data.files;
                    // if(files !== ""){
                    //     var path = files.split(",");
                    //     for(var i = 0; i < path.length; i++){
                    //         filename = filename + path[i].substring(path[i].indexOf("_") + 1,path[i].lastIndexOf(".") - 3) + path[i].substring(path[i].lastIndexOf(".")) + ",";
                    //     }
                    //     filename = filename.substring(0,filename.length - 1);
                    // }
                    // $("<div class='layui-input-inline' style='width: 68%'><div class='layui-input fileclass'>"+filename+"</div></div>").insertAfter(pNode.children[0]);
                }
            })
            // var files = [];
            //第一种方法添加用户
            form.on('submit(*)', function (data) {
                var field = data.field//当前容器的全部表单字段，名值对形式：{name: value}
                var formData = getFormData();
                var index = layer.msg('数据提交中，请稍候', {icon: 16, time: false, shade: 0.6});
                $("#pushButton").addClass("layui-btn layui-btn-disabled").prop("disabled", true);
                $.ajax({
                    type: "post",
                    url: "<%=request.getContextPath()%>/rest/base/updateLaw",
                    data: formData,
                    processData: false,			//对数据不做处理
                    dataType: "json",
                    cache: false,      			//上传文件不需要缓存
                    contentType: false,
                    success: function (obj) {
                        setTimeout(function () {
                            layer.close(index);
                            if (obj === true) {
                                layer.msg('修改成功');
                            } else {
                                layer.msg(obj.errorMsg);
                            }
                        }, 2000);
                        setTimeout(function () {
                            var indexs = parent.layer.getFrameIndex(window.name);//获取当前弹出层的层级
                            parent.layer.close(indexs);//关闭弹出层
                        }, 4000);
                    }
                })
                return false;
            });
        });
    }
</script>
</body>
</html>